package com.itheima.mycollection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86131
 * Date: 2023-11-25
 * Time: 15:56
 */
public class A03_CollectionDemo3 {
    public static void main(String[] args) {
        //1.创建集合并添加元素
        Collection<String> coll = new ArrayList<>();
        coll.add("aaa");
        coll.add("bbb");
        coll.add("ccc");
        coll.add("ddd");
        coll.add("eee");

        //获取迭代器对象
        //迭代器好比一个箭头.默认指向0索引处
        /*Iterator<String> it = coll.iterator();

        //3.利用循环不断夺取集合每个元素
        while(it.hasNext()){//判断当前索引是否有元素
            //.next方法有两件事情:获取元素并移动指针
            String str = it.next();
            System.out.println(str);
        }*/

        /*for (String s : coll) {
            s = "qqq";
        }
        System.out.println(coll);*/

       coll.forEach(string -> System.out.println(string));
    }
}
